package com.prime.tutorial.moviestore.service.techsupport;

import com.prime.tutorial.moviestore.Constants;
import com.prime.tutorial.moviestore.dao.DeviceDAO;
import com.prime.tutorial.moviestore.dao.StateDAO;
import com.prime.tutorial.moviestore.domain.Device;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Implemetation of {@link TechSupportService}
 * @author vasylja
 */
@Service
public class TechSupportServiceImpl implements TechSupportService{
    private DeviceDAO deviceDAO;
    private StateDAO stateDAO;

    @Autowired
    public TechSupportServiceImpl(DeviceDAO deviceDAO, StateDAO stateDAO) {
        this.deviceDAO = deviceDAO;
        this.stateDAO = stateDAO;
    }

    public void removeDevice(Device device) {
        //TODO Implement
        device.setState(stateDAO.findByType(Constants.STATE_ON_STORAGE).get(0));
        deviceDAO.update(device);
    }

    public void installDevice(Device device) {

        device.setState(stateDAO.findByType(Constants.STATE_ENABLED).get(0));
        deviceDAO.update(device);
    }

    public List<Device> findDevicesToInstall() {
        return deviceDAO.findByState(stateDAO.findByType(Constants.STATE_APPROVED_INSTALLATION).get(0));
    }

    public List<Device> findDevicesToRemove() {
        return deviceDAO.findByState(stateDAO.findByType(Constants.STATE_PLANNED_REMOVAL).get(0));
    }
}
